#
# packet template
#
# Copyright (C) 2009 by chrisv <me@cv.gd>
#          
# See CREDITS for details about who has contributed to this project.
#
# For further information about the pdaXrom project and license conditions
# see the README file.
#

SPU_MEDIALIB_VERSION=svn
SPU_MEDIALIB=spu-medialib-${SPU_MEDIALIB_VERSION}
SPU_MEDIALIB_MIRROR=http://spu-medialib.svn.sourceforge.net/svnroot/spu-medialib/trunk/spu-medialib/
SPU_MEDIALIB_DIR=$BUILD_DIR/spu-medialib-${SPU_MEDIALIB_VERSION}
SPU_MEDIALIB_ENV="$CROSS_ENV_AC"

SPU_INCLUDE_PATH=/opt/powerpc-linux/toolchain/lib/gcc/spu/4.3.3/include/

build_spu_medialib() {
    test -e "$STATE_DIR/spu-medialib.installed" && return
    banner "Build spu-medialib"
    download_svn $SPU_MEDIALIB_MIRROR $SPU_MEDIALIB
    rm -rf $SPU_MEDIALIB_DIR
    mkdir $SPU_MEDIALIB_DIR
    cp -a $SRC_DIR/$SPU_MEDIALIB $BUILD_DIR
    apply_patches $SPU_MEDIALIB_DIR $SPU_MEDIALIB
    pushd $TOP_DIR
    # fix broken symlink to speutils
    ln -sf ../../../speutils-0.1/include/speutils $SPU_MEDIALIB_DIR/spu/src/speutils
    cd $SPU_MEDIALIB_DIR
    (
    sh update.sh    
    eval \
	$CROSS_CONF_ENV \
	$SPU_MEDIALIB_ENV \
	./configure --build=$BUILD_ARCH --host=$TARGET_ARCH \
	    --prefix=/usr \
	    --sysconfdir=/etc \
	    || error
    ) || error "configure"

    # need to patch the makefiles for missing OBJEXT, don't know why :-(
    #sed -i 's/^OBJEXT = $/OBJEXT = o/' spu/Makefile spu/src/Makefile

    make $MAKEARGS || error

    install_sysroot_files || error
    
    cd $TARGET_LIB
    
    # not sure whether we need the .a and .la's...
    for lib in libtiles.so.0.0.0 libspu-medialib.so.0.1.0 libtiles.la libtiles.a libspu-medialib.a libspu-medialib.la; do
	$INSTALL -D -m 644 $lib $ROOTFS_DIR/usr/lib/$lib || error	
    done
    
    ln -sf libtiles.so.0.0.0 $ROOTFS_DIR/usr/lib/libtiles.so.0
    ln -sf libtiles.so.0.0.0 $ROOTFS_DIR/usr/lib/libtiles.so
    $STRIP $ROOTFS_DIR/usr/lib/libtiles.so.0.0.0    
    
    ln -sf libspu-medialib.so.0.1.0 $ROOTFS_DIR/usr/lib/libspu-medialib.so.0
    ln -sf libspu-medialib.so.0.1.0 $ROOTFS_DIR/usr/lib/libspu-medialib.so
    $STRIP $ROOTFS_DIR/usr/lib/libspu-medialib.so.0.1.0

    popd
    touch "$STATE_DIR/spu-medialib.installed"
}
build_spu_medialib
